import {useQuery,useMutation} from "@tanstack/react-query"
import request from './request'
const useRequest = (axiosOptions=[],queryOptions={}) => {
  const axiosQuery = ({queryKey})=>{
      let payload = {}
      queryKey.map((params)=>{
          payload = {...payload,...params}
      })
      return request(payload)
  }
  const axiosParams = Array.isArray(axiosOptions) ? axiosOptions : [axiosOptions]
  const basicQueryOptions = {
      initialData: {data: {}},
  }
  // @ts-ignore
    return useQuery(axiosParams,axiosQuery,{...basicQueryOptions,...queryOptions})
}
const useAction = (axiosOption={},queryOptions,transform) => {
    const axiosAction = (data={})=>{
        return request({data,...axiosOption,...(transform && transform(data))})
    }
    return useMutation(axiosAction,queryOptions)
}
export {
    useRequest,
    useAction
};